﻿#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar code KEY_TABLE[] = { 0xee,0xde,0xbe,0x7e,
						0xed,0xdd,0xbd,0x7d,
												0xeb,0xdb,0xbb,0x7b,
												0xe7,0xd7,0xb7,0x77 };//°´¼ü¼üÖµ±í
uchar code TABLE[] = { 0x3F,0x06,0x5B,0x4F,
										0x66,0x6d,0x7d,0x07,
										0x7f,0x6f,0x77,0x7c,
										0x39,0x5e,0x79,0x71 };//¹²Òõ¼«ÊýÂë¹Ü±àÂë±í

uchar temp, key, num, i;

void delay1()  //¶ÌÑÓÊ±
{
	uint n = 5; while (n--);
}

void delays()//³¤ÑÓÊ±
{
	uint n = 100; while (n--);
}

void main()
{

	while (1)
	{
		//P1=0xF0;//ÖÃÐÐÎª0ÁÐÎª1
		P1 = 0xf0;
		P2 = 0x00;//ÏûÓ°×Ó
		if (P1 != 0xf0)
		{
			delays();//ÏûÕñ¶¯
			if (P1 != 0xf0)
			{
				temp = P1;//´¢Öµ
				P1 = 0x0f;//ÁÐÎª0£¬ÐÐÎª1
				key = temp | P1;
				for (i = 0; i < 16; i++)
				{
					if (key == KEY_TABLE[i])
					{
						num = i; break;
					}
				}

				P3 = 0xfd;//Î»Ñ¡
				P2 = TABLE[num / 10];
				delay1();
				P3 = 0xfe;
				P2 = TABLE[num % 10];
				delay1();
			}
		}
	}
}
